package com.situ.ftbserver.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.situ.ftbserver.model.Course;
import com.situ.ftbserver.model.search.CourseSearchBean;
import com.situ.ftbserver.util.PaginateInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper

public interface CourseMapper extends BaseMapper<Course> {
    List<Course> findAll(CourseSearchBean csb);

    int delete(Integer[] ids);

    @Select("SELECT c.name,c.description, COUNT(r.id) AS reserve_count ,co.`name` AS coachName,co.photo AS url " +
            "FROM course c " +
            "LEFT JOIN reserve r ON c.id = r.course_id " +
            "LEFT JOIN coach co ON c.coach_id = co.id " +
            "GROUP BY c.id " +
            "ORDER BY reserve_count DESC " +
            "LIMIT 10;")
    List<Map<String, Object>> getPopularCourse();
}
